/* 
  路由配置
*/

//页面布局
import Layout from "../views/layout/index.vue";

const routes = [
  {
    path:'/',redirect: '/login'
  },
  {
    path: '/login',
    component: () => import('../views/login.vue'),
  },
  {
    path: '/common',
    component: Layout, 
    redirect:'/common/index',     
    children: [      
      {
        path: 'index',
        component: () => import('../views/index.vue'),
      },
      {
        path: 'content/:id',
        component: () => import('../views/content.vue'),
        props: router => ({ //props传参
          id: router.params.id //动态参数
        })
      },
      {
        path: 'message',
        component: () => import('../views/message.vue'),
      },
      {
        path: 'logInfo',
        component: () => import('../views/logInfo.vue'),
      },
      {
        path: 'opLog',
        component: () => import('../views/opLog.vue'),
      },
      {
        path: 'explain',
        component: () => import('../views/explain.vue'),
      },
      {
        path: 'role',
        component: () => import('../views/role.vue'),
      }        
    ],    
    //无token跳转登陆页
    beforeEnter: (to, from, next) => {
      const token = sessionStorage.getItem('token');
      if(!token){
        return next('/login');
      }
      next()
    },   
  },    
  {
    path: '*', //404页面
    component: () => import("../views/N404/index.vue")
  }
]

export default routes